package top.viya.hello2.redis.list;

import jakarta.annotation.Resource;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

//@Component
public class ListApplicationRunner implements ApplicationRunner {

    @Resource(name = "stringRedisTemplate")
    private RedisTemplate<String, String> stringRedisTemplate;

    @Resource(name = "jsonRedisTemplate")
    private RedisTemplate<String, Object> jsonRedisTemplate;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        stringRedisTemplate.opsForList().leftPush("kl1:str", "test");
        jsonRedisTemplate.opsForList().leftPush("kl2:json", "test");

//        stringRedisTemplate.opsForValue().set("k1:str", "hello world");
//        jsonRedisTemplate.opsForValue().set("k1:json", "hello world");
//
//        String rs1 = stringRedisTemplate.opsForValue().get("k1:str");
//        String rs2 = (String) jsonRedisTemplate.opsForValue().get("k1:json");
//        System.out.println(rs1);
//        System.out.println(rs2);
//
//        stringRedisTemplate.opsForValue().set("k2:str", "1");
//        jsonRedisTemplate.opsForValue().set("k2:json", 1);
//
//        Integer n1 = stringRedisTemplate.opsForValue().get("k2:str").transform(Integer::parseInt);
//        Integer n2 = (Integer) jsonRedisTemplate.opsForValue().get("k2:json");
//        System.out.println(n1);
//        System.out.println(n2);


    }
}
